<?php

  if (isset($_POST['submit0'])) { // If password entered...
    $word = $_POST['password']; // Variable set as entered password
    setcookie('textadmin', $word, time() + 31536000); // Cookie is set
  } else { // If password form filled in previously...
    if (isset($_COOKIE['textadmin'])) { // Check for cookie
      $word = $_COOKIE['textadmin']; // Variable set as cookie
    }
  }

?>

<?php $thisPage = "menu"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Create a new navigation button</title>
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>

<div id="wrap">

<?php

// Start password routine
  include_once('password.php');
  if ($word != $le_password) {

?>

<!-- password form //-->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
<b>Enter password:</b>
<br />
<input type="password" name="password" size="25" maxlength="25" />
<br />
<input type="submit" name="submit0" value="Submit" />
</p>
</form>
<!-- password form_eof //-->

<?php

    // Routine to display password entry error message.
    if (isset($_POST['submit0'])) {
      if ($_POST['password'] != $le_password) {
        echo '<p">Incorrect password!</p>';
      }
    }

  } else {
// End password routine

?>

<?php include_once('navigation.php'); ?>

<?php

  if (isset($_POST['submit'])) { // Handle the form

    // Create the variable for ThisPage2
    $thispage2 = $_POST['thispage2'];

    // Create the link text
    $linktext2 = $_POST['linktext2'];
    $linktext2 = stripslashes($linktext2);
    // Trim whitespace at ends
    $linktext2 = trim($linktext2);
    // Strip out hyphens for page variable
    $thispage3 = str_replace("-", "", $thispage2);
    // Make lowercase and trim whitespace at ends
    $thispage3 = trim(strtolower($thispage3));

    // Define the HTML for a button in menu.php (as class template)
    $buttonHTML = '<?php $' . $thispage3 . ' = new Button; $' . $thispage3 . '->ThisPage = $le_page; $' . $thispage3 . '->ThisPage2 = "' . $thispage2 . '"; $' . $thispage3 . '->LinkText = "' . $linktext2 . '"; $' . $thispage3 . '->Template2(); ?>';

    $button = $buttonHTML . "\n";

    // Path to the .php file (to write the template)
    $filename = "../includes/menu.php";

    // Write the contents
    $fp = fopen($filename, "a") or die("Couldn't open $filename.");
    fwrite($fp, $button);
    fclose($fp);

    // Feedback
    $response = "The file menu.php was updated.";
  }

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Existing page name (no file suffix)<br />
<input type="text" name="thispage2" id="thispage2" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['thispage2']; ?>" maxlength="60" />
<br />
Desired link text<br />
<input type="text" name="linktext2" id="linktext2" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['linktext2']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Create button" />
</form>

<?php echo $response; ?>

<?php include_once('list-all.php'); ?>

<?php

  } // Required for password routine

?>

<div style="clear: both;"></div>
</div>

</body>
</html>